#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
//#include"selection.h"

 void swap (int *a, int *b);
 void selection (int *p, int n );

int main()
{
    int n, i, j, *p;
    
    //input an array of numbers
    printf ("How many elements do you want to input? - ");
    scanf ("%d", &n); 
    p= malloc(n*sizeof (int) );
    for (i=0; i<n; i++)
    {
        printf("Enter the element no %d: ", i+1);
        scanf("%d", p+i);
        }
    selection (p, n);
    printf (" \n");
    for (i=0; i<n; i++)
        printf (" %d", *(p+i));
    getch();
    return 0;
}

        
    void swap (int *a, int *b)
    {
         int tmp;
         tmp=*a;
         *a=*b;
         *b=tmp;
         } 


    void selection (int *p, int n )
    {
         int i, j, pos, min;
    for (i=0; i<n-1;i++)
    {
         pos=i;
         min=*(p+i);
         for (j=i+1; j<n; j++)
         {
             if (*(p+j)<min)
             {
              min=*(p+j);
              pos=j;
              
             }
             swap(p+i, p+pos);
         }
    }
    }
